// src/renderer/src/router/index.js
import { createRouter, createWebHashHistory } from 'vue-router'

// 布局组件
const Layout = () => import('@/components/Layout/Layout.vue')


// 动态导入视图组件（代码分割）
const loadView = (view) => () => import(`@/views/${view}/${view}.vue`)

export default createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/login',
      name: 'login',
      component: loadView('Login')
    },
    {
      path: '/',
      redirect: '/home',
      component: Layout,
      children: [
        {
          path: 'home',
          name: 'home',
          component: loadView('Home')
        }
      ]
    },
    {
      path: '/incomeAndExpenditure',
      name: 'incomeAndExpenditure',
      redirect: '/incomeAndExpenditure/incomeAndExpenditure',
      component: Layout,
      children: [
        {
          path: 'incomeAndExpenditure',
          component: loadView('IncomeAndExpenditure')
        }
      ]
    },
    {
      path: '/category',
      name: 'category',
      redirect: '/category/category',
      component: Layout,
      children: [
        {
          path: 'category',
          component: loadView('Category')
        }
      ]
    },
    {
      path: '/assets',
      name: 'assets',
      redirect: '/assets/assets',
      component: Layout,
      children: [
        {
          path: 'assets',
          component: loadView('Assets')
        }
      ]
    },
    {
      path: '/settings',
      name: 'settings',
      redirect: '/settings/settings',
      component: Layout,
      children: [
        {
          path: 'settings',
          component: loadView('Settings')
        }
      ]
    },
    {
      path: '/notes',
      name: 'notes',
      redirect: '/notes/notes',
      component: Layout,
      children: [
        {
          path: 'notes',
          component: loadView('Notes')
        }
      ]
    },
    {
      path: '/help',
      name: 'help',
      redirect: '/help/help',
      component: Layout,
      children: [
        {
          path: 'help',
          component: loadView('Help')
        }
      ]
    },
    {
      path: '/password',
      name: 'password',
      redirect: '/password/password',
      component: Layout,
      children: [
        {
          path: 'password',
          component: loadView('Password')
        }
      ]
    },
    {
      path: '/:pathMatch(.*)*',
      redirect: '/'
    }
  ]
})